package com.slwu.common;

import java.io.Serializable;

public class RESP<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private String excId;
    private Integer code;
    private String msg;
    private String errType = "";
    private T data;
    private Long time;

    public RESP() {
    }

    public Long getTime() {
        return this.time;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    public String getExcId() {
        return this.excId;
    }

    public void setExcId(String excId) {
        this.excId = excId;
    }

    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getErrType() {
        return this.errType;
    }

    public void setErrType(String errType) {
        this.errType = errType;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <M> RESP<M> ok(M data) {
        RESP<M> resp = new RESP();
        resp.setData(data);
        resp.setCode(200);
        resp.setTime(System.currentTimeMillis());
        return resp;
    }

    public static <M> RESP<M> ok(String msg) {
        RESP<M> resp = new RESP();
        resp.setMsg(msg);
        resp.setCode(200);
        resp.setTime(System.currentTimeMillis());
        return resp;
    }

    public static <M> RESP<M> ok(M data, String msg) {
        RESP<M> resp = new RESP();
        resp.setData(data);
        resp.setCode(200);
        resp.setMsg(msg);
        resp.setTime(System.currentTimeMillis());
        return resp;
    }

    public static <M> RESP<M> warn(int errCode, String errMsg) {
        RESP<M> resp = new RESP();
        resp.setErrType("W");
        resp.setMsg(errMsg);
        resp.setCode(errCode);
        resp.setTime(System.currentTimeMillis());
        return resp;
    }

    public static <M> RESP<M> error(int errCode, String errMsg) {
        RESP<M> resp = new RESP();
        resp.setErrType("E");
        resp.setMsg(errMsg);
        resp.setCode(errCode);
        resp.setTime(System.currentTimeMillis());
        return resp;
    }
}
